﻿
namespace LifeInSharePoint.Common
{
    using System;

    using Microsoft.Practices.SPG.Common.Logging;

    /// <summary>
    /// The globe base logger.
    /// </summary>
    public class SPBaseLogger : SharePointLogger
    {
        #region Constants and Fields

        /// <summary>
        /// The maximum number of characters allowed by messages in the windows event log
        /// </summary>
        private const int MaximumNumberOfChars = 32766;

        #endregion

        #region Helper Methods

        /// <summary>
        /// Build an exception message for an exception that contains more information than the
        /// normal Exception.ToString().
        /// </summary>
        /// <param name="exception">
        /// The exception to format.
        /// </param>
        /// <param name="customErrorMessage">
        /// Any custom error information to include.
        /// </param>
        /// <returns>
        /// The error message.
        /// </returns>
        protected virtual string BuildExceptionMessage(Exception exception, string customErrorMessage)
        {
            string errorMessage = this.BuildExceptionMessage(exception, customErrorMessage);

            // trim the message so that it doesn't exceed the maximum number of characters alowed in the windows event log          
            if (errorMessage.Length > MaximumNumberOfChars)
            {
                errorMessage.Remove(MaximumNumberOfChars - 1);
            }

            return errorMessage;
        }

        #endregion
    }
}